<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"  
		xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
<meta charset="UTF-8">
<title>首页</title>
<link id="easyuiTheme"  rel="stylesheet" href="webjars/easyui-186/1.8.6/themes/material/easyui.css" />
<link rel="stylesheet" href="webjars/easyui-186/1.8.6/themes/icon.css" />
<link rel="stylesheet" href="static/custom.css" />
<script type="text/javascript" src="webjars/easyui-186/1.8.6/jquery.min.js"></script>
<script type="text/javascript" src="webjars/easyui-186/1.8.6/jquery.easyui.min.js"></script>
<script type="text/javascript" src="webjars/easyui-186/1.8.6/locale/easyui-lang-zh_CN.js"></script>	
<script type="text/javascript" src="static/custom.js"></script>	
<script type="text/javascript" src="static/easycustom.js"></script>	
<script type="text/javascript">

var data1 = [{
	text: '成绩管理',
    state: 'open',
    children: [{
        text: '班级成绩录入',
        href:'grade/classGrade',    
    },{
        text: '个人成绩录入',
        href:'grade/xsClassGrade'
    },{
        text: '班级成绩查询',
        href:'grade/allGrade'
    }]
},{
    text: '系统设置',
    children: [{
        text: '课程管理',
        href:'course/manage',
    },{
        text: '班级管理',
        href:'tbclass/manage',
    },{
        text: '学生管理',
        href:'xuesheng/manage',
    },{
        text: '教师管理',
        href:'teacher/laoshi',
    }]
}];

var data2 = [{
	text: '成绩查询',
    state: 'open',
    children: [{
        text: '个人成绩查询',
        href:'grade/peasonGrade',
    },{
        text: '班级成绩查询',
        href:'grade/peasonGradeCjb',
    }]
}];

var data3 = [{text: '成绩管理',
    state: 'open',
    children: [{
        text: '班级成绩录入',
        href:'grade/classGrade',    
    },{
        text: '个人成绩录入',
        href:'grade/xsClassGrade'
    },{
        text: '班级成绩查询',
        href:'grade/allGrade'
    }]
}];


function showTab(container, title, src) {
	var tabContainer = $(container);
	if (tabContainer.tabs('exists', title)) {
		var tab = tabContainer.tabs('getTab', title); 
		var currentTab = tabContainer.tabs('getSelected');
		if (tab == currentTab) {
			tab.panel('refresh', src);
		} else {
			tabContainer.tabs('select', title);
		}
	} else {
		tabContainer.tabs('add', {
			'title' : title,
			'href' : src,
			'closable' : true ,
		});
	}
}

function changeTheme(themeName) {

    var $easyuiTheme = $('#easyuiTheme');

    var url = $easyuiTheme.attr('href');

    var href = url.substring(0, url.indexOf('themes')) + 'themes/' + themeName + '/easyui.css';

    $easyuiTheme.attr('href', href);

  };

$(function(){
	$('#sm').sidemenu({
	     data: data1,
	     fit:true,
	     multiple:false,
	     onSelect: function(node){
	    	 if (node.text != undefined && node.href != undefined) {
					showTab('#tt', node.title ? node.title : node.text, node.href);
			 }
	     }
	    
	 });
	
	$('#sm2').sidemenu({
	     data: data2,
	     fit:true,
	     multiple:false,
	     onSelect: function(node){
	    	 if (node.text != undefined && node.href != undefined) {
					showTab('#tt', node.title ? node.title : node.text, node.href);
			 }
	     }
	    
	 });
	

	$('#sm3').sidemenu({
	     data: data3,
	     fit:true,
	     multiple:false,
	     onSelect: function(node){
	    	 if (node.text != undefined && node.href != undefined) {
					showTab('#tt', node.title ? node.title : node.text, node.href);
			 }
	     }
	    
	 });
})


function menuHandler(item) {
        if(item.name=='logout'){
        	window.location.href='logout';
        }else if(item.name=='xgpwd'){
        	var dialog=$('<div style="display:none;">');
    		dialog.appendTo($('body'));
    		dialog.dialog({
    		    title: '修改密码',
    		    width:300,
    		    height:180,
    		    cache: false,
    		    modal: true,
    		    href:'pwd/edit',
    		    onClose:function(){
    		    	dialog.dialog('destroy');
    		    	dialog.remove();
    			},
    			buttons:[{
    				iconCls:'icon-save',
					text:'保存',
					handler: function(e){
						var form=$(this).closest('div.window').children('div.window-body').find('form');
						var formDom = form[0];
						var pwd1 = formDom.password1.value;
						var pwd2=formDom.password2.value;
						var params=form.serialize();
						if(pwd1!=pwd2){
							$.messager.alert('提示','两次输入密码不一致','info');
							var box =form.children('dl').children('dd').children('input');
							box.passwordbox({
							    handler: function(e){
							        $(e.data.target).passwordbox('clear');
							    }
							})
							return;
						}
						$.post('pwd/save',params,function(data){
							dialog.dialog('close');
							window.location=window.location.pathname+'?logout';
						})
						
					}		
				},{
					iconCls:'icon-cancel',
					text:'退出',
					handler: function(){
						dialog.dialog('close');
					}				
				}]
    		});
    		dialog.dialog('open');
        }
}


</script>
<style type="text/css">
	.top {
		display: flex;
		flex-direction: column;
		justify-content:center;
	}
	
	
</style>
</head>
<body class="easyui-layout">
	<div class="top" data-options="region:'north'" style="height:65px;">
		<div style="padding:10px 40px; display: flex; flex-direction: row; justify-content: space-between;align-items:center;">
				<span style="font-size: 1.5em;">EasyUI-成绩管理系统</span>
				
				<span><a class="easyui-menubutton" data-options="hasDownArrow:false">欢迎你</a><a href="javascript:void(0)" id="mb" class="easyui-menubutton" style="margin-right: 30px;" data-options="menu:'#mm'"><span sec:authentication="principal.name"></span></a><input class="easyui-switchbutton"  style="margin-right: 30px;" data-options="onText:'黑夜',offText:'白天',
				onChange:function(e){
					if(e){
						changeTheme('black')
					}else{
						changeTheme('material')
					}
				}
				"></span>
		</div>
	</div>
	<div data-options="region:'south'" style="height:60px;text-align: center;"> <p>19级软件3班-孙泽鑫韬</p></div>
	<!-- <div data-options="region:'east',iconCls:'icon-reload',title:'East',split:true" style="width:100px;"></div> -->
	<div data-options="region:'west',title:'操作',split:true" style="width:200px;">
		
		<div sec:authorize="hasRole('ROLE_ADMIN')" style="height: 100%">
    		<div id="sm" ></div>
		</div>
		
		<div sec:authorize="hasRole('ROLE_STUDENT')" style="height: 100%">
    		<div id="sm2" ></div>
		</div> 
		
		<div sec:authorize="hasRole('ROLE_TEACHER')" style="height: 100%">
    		<div id="sm3" ></div>
		</div> 
			
	</div>
	<div id="center" data-options="region:'center'" style="background:#eee;">
		 <div id="tt" class="easyui-tabs"  data-options="fit:true">
		    <div title="首页" style="padding:20px;display:none;">
		      	  欢迎你使用本网站！
		    </div>
		</div>
	</div>
	
	<div id="mm"  data-options="onClick:menuHandler" style="width:150px;">
	    <div data-options="name:'xgpwd'">修改密码</div>
	    <div data-options="name:'logout'">注销</div>
	</div>
</body>
</html>